package com.example.mylibrary.testActivity.Basemodule;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import androidx.annotation.DimenRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

public abstract class Base01_Activity extends AppCompatActivity {
    /***获取TAG的activity名称**/
    public final String TAG = this.getClass().getSimpleName();
    public float getDimension(@DimenRes int res) {
        return getResources().getDimension(res);
    }
    /***获取颜色**/
    public int myGetColor(int color){
        return getResources().getColor(color);
    }
    /***获取图片资源**/
    public Drawable myGetDrawable(int drawable){ return getResources().getDrawable(drawable); }
    /***获取字符串**/
    public String myGetString(int string){
        return getResources().getString(string);
    }
    /*** replace 的方式在 Activity 中添加 Fragment**/
    public void replaceFragment(int view, Fragment fragment) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();   // 开启一个事务
        transaction.replace(view, fragment);
        transaction.commit();
    }



















    /**
     * 生成Long 类型唯一ID
     */
    public synchronized  Long getId() {
        AtomicLong id = null;
        //如果需要更长 或者更大冗余空间, 只需要 time * 10^n   即可
        //当前可保证1毫秒 生成 10条不重复
        Long time = Long.valueOf(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())) * 10;
        if (id == null) {
            id = new AtomicLong(time);
            return id.get();
        }
        if (time <= id.get()) {
            id.addAndGet(1);
        } else {
            id = new AtomicLong(time);
        }
        return id.get();
    }
}
